import { Controller, Get, Post, UseInterceptors, UploadedFile, UseGuards } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { ApiUseTags, ApiOperation, ApiConsumes, ApiImplicitBody , ApiModelProperty, ApiImplicitParam, ApiBearerAuth   } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';

// class FileUploadDto {
//   @ApiModelProperty ({ type: 'string', format: 'binary' })
//   file: BinaryType
// }

class FileUploadDto {
  @ApiModelProperty({ type: 'string', format: 'binary', description: '文件上传的数据' })
  file: string;
  // file: Binary
}


@Controller()
@ApiUseTags('公共功能')
@UseGuards(AuthGuard('jwt')) 
@ApiBearerAuth()
export class AppController {
  @Post('upload')
  @UseInterceptors(FileInterceptor('file'))
  @ApiOperation({ title: '文件上传' })
  @ApiConsumes('multipart/form-data')
  @ApiImplicitBody({
    name: 'file',
    description: '文件上传',
    type: FileUploadDto,
    required: true
  })
  async upload(@UploadedFile('file') file) {
    return {
      ...file,
      name: file ? file.url : '频率太快啦', 
    }
  }
}
